/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ex02;

import ex01.DBUtils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author 20060074
 */
public class DeleteData {

    public static void main(String[] args) {

        Connection con = null;
        PreparedStatement pst = null;
        PreparedStatement pst2 = null;

        try {
            con = DBUtils.openAcessConection("Northwind97");
            pst = con.prepareStatement("DELETE FROM ORDERS WHERE OrderID = ?");
            pst2 = con.prepareStatement("DELETE FROM [Order Details] WHERE OrderID = ?");

            pst.setInt(1, 10248);
            pst2.setInt(1, 10248);
            
            con.setAutoCommit(false);
                      
            pst.executeUpdate();
            pst2.executeUpdate();            
            con.commit();
            
        } catch (SQLException ex) {
            try {
                con.rollback();                
            } catch (SQLException ex1) {
                Logger.getLogger(DeleteData.class.getName()).log(Level.SEVERE, null, ex1);
            }
            System.err.print("Erro:" + ex);
        } catch (ClassNotFoundException ex) {
            System.err.print("Erro driver");
        } finally {
            try {            
                if (con != null) con.close();
            } catch (SQLException ex) {
                System.out.println(ex);
            } 
        } 
          

    }
}
